Please make sure these libraries below are installed in your computer before runnnign this script
# 0. Import
import numpy as np
import pandas as pd
import os
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
sns.set_style("ticks")
plt.rcParams["figure.figsize"] = [18,9]
%config InlineBackend.figure_format = 'retina'
sns.set_style("ticks")
plt.rcParams["image.cmap"] = "viridis"
import IQC
folder = "./test_data/"
file_paths = os.listdir(folder)
file_paths.sort()
file_paths = [os.path.join(folder, i) for i in file_paths if not "DS_Store" in i]
file_paths
BF_path_list = [i for i in file_paths if "bf" in i]
GFP_path_list = [i for i in file_paths if "gfp" in i]
print(BF_path_list)
print(GFP_path_list)
## Step 1
# 1.0 set file path
BF_file = BF_path_list[2]
GFP_file =GFP_path_list[2]
print(BF_file, GFP_file)
from importlib import reload
reload(IQC)
img = IQC.OneArea()
img.getBFImageFromPath(BF_file, plot=False)
img.getGreenImageFromPath(GFP_file, plot=False)
# 1.2.1 show image
plt.subplot(1,2,1)
img.plotBF()
plt.title("Bright Field image")
plt.subplot(1,2,2)
img.plotGreen()
plt.title("GFP image")
plt.show()
# 2.1 Binalization by Otsu methoda
color_for_cell_detection = "BF"
threshold_adjustment = 0
img.binarizeImageByOtsu(color=color_for_cell_detection,
threshold_adjustment=threshold_adjustment, plot=True)
if Binalization did not work, please try binarize again with new parameter for "threshold_adjustment"
# 2.2 Object detection
segmentation_scale = 1
img.detectObjects(color=color_for_cell_detection,
segmentation_scale=segmentation_scale)
if objects are not properly detected, please change "segmentation_scale" and try object detection again In many case, detected objects include debris and doublet cells. We have to remove these debris and doublet cells before quantification.
min_size = 10
max_size = 70
img.filterObjectsBySize(color=color_for_cell_detection,
min_size=min_size, max_size=max_size, plot=True)
If the cells are not appropriately identified, go back and change parameters for thresholding
img.plotValuesPerObjects(segment_color=color_for_cell_detection,
value="green_mean_intensity", scale_log=True)
result = img.getAllValuesPerObjects(color_for_cell_detection, remove_noise=True)
result.head()
If you have some images, quantification can be done in the same way with the parameters acquired by the pilot analysis below.
# make function for the pipeline
def processAll(file_path_for_BF, file_path_for_GFP):
print(f"BF image: {file_path_for_BF}")
print(f"GFP image: {file_path_for_GFP}")
img_ = IQC.OneArea()
img_.getBFImageFromPath(file_path_for_BF, plot=False)
img_.getGreenImageFromPath(file_path_for_GFP, plot=False)
img_.binarizeImageByOtsu(color=color_for_cell_detection,
threshold_adjustment=threshold_adjustment,
plot=False)
img_.detectObjects(color="BF", segmentation_scale=segmentation_scale,
plot=False)
img_.filterObjectsBySize(color=color_for_cell_detection,
min_size=min_size,
max_size=max_size,
plot=True)
plt.show()
res = img_.getAllValuesPerObjects(segment_color=color_for_cell_detection)
res["file_path_BF"] = file_path_for_BF
res["file_path_Green"] = file_path_for_GFP
return res
# process all images.
results = []
for BF_path, GFP_path in zip(BF_path_list, GFP_path_list):
result = processAll(BF_path, GFP_path)
results.append(result)